/**
 * @param {string} s
 * @return {string}
 */
var decodeString = function(s) {
  const reg = /(\d+)\[(\w+)\]/g;
  function replaceString(s) {
    s = s.replace(reg, function(...payload) {
      return payload[2].repeat(payload[1]);
    });
    if(reg.test(s)) {
      // 递归
      return replaceString(s);
    } else {
      return s;
    }
  }
  return replaceString(s);
};
let s = "3[a]2[bc]";
console.log(decodeString(s));
s = "3[a2[c]]";
console.log(decodeString(s));
s = "2[abc]3[cd]ef";
console.log(decodeString(s));
s = "abc3[cd]xyz";
console.log(decodeString(s));
// s = "100[leetcode]";
// console.log(decodeString(s));
